home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-30 | 3.5 KB | 123 lines | [TEXT/CWIE] |
- unit preferences;
-
- interface
-
- uses
- Types,
- Folders,
- Script,
- Processes,
- Files;
-
- procedure LoadPreferences(thePreferences:Ptr;sizeOfPreferences:longint;preferencesName:Str32);
- procedure SavePreferences(thePreferences:Ptr;sizeOfPreferences:longint;preferencesName:Str32);
- function ApplicationCreator:OSType;
-
- implementation
-
- function ApplicationCreator:OSType;
- var
- thisProcess:ProcessSerialNumber;
- theProcessInfo:ProcessInfoRec;
- processError:OSErr;
- temp:OSType;
- begin
- temp:='Err.';
- theProcessInfo.processInfoLength:=SizeOf(ProcessInfoRec);
- theProcessInfo.processName:=nil;
- theProcessInfo.processAppSpec:=nil;
- thisProcess.highLongOfPSN:=0;
- thisProcess.lowLongOfPSN:=kCurrentProcess;
- processError:=GetProcessInformation(thisProcess,theProcessInfo);
- if processError=noErr then
- temp:=theProcessInfo.processSignature;
- ApplicationCreator:=temp;
- end;
-
- procedure LoadPreferences(thePreferences:Ptr;sizeOfPreferences:longint;preferencesName:Str32);
- const
- fnfErr=-43;
- var
- theError:OSErr;
- prefVolRef,prefFileRef:integer;
- prefDirID,jcgDirID:longint;
- jcgDirSpec,prefFileSpec:FSSpec;
- theCIPB:CInfoPBRec;
- jcgDirName:Str32;
- begin
- jcgDirName:='jcg';
- theError:=FindFolder(kOnSystemDisk,kPreferencesFolderType,true,prefVolRef,prefDirID);
- if theError=noErr then begin
- theError:=FSMakeFSSpec(prefVolRef,prefDirID,jcgDirName,jcgDirSpec);
- if (theError=noErr) or (theError=fnfErr) then begin
- if theError=fnfErr then
- theError:=FSpDirCreate(jcgDirSpec,smSystemScript,jcgDirID)
- else begin
- theCIPB.ioCompletion:=nil;
- theCIPB.ioNamePtr:=@jcgDirName;
- theCIPB.ioVRefNum:=prefVolRef;
- theCIPB.ioDrDirID:=prefDirID;
- theCIPB.ioFDirIndex:=0;
- theError:=PBGetCatInfoSync(@theCIPB);
- jcgDirID:=theCIPB.ioDrDirID;
- end;
- if theError=noErr then begin
- theError:=FSMakeFSSpec(prefVolRef,jcgDirID,preferencesName,prefFileSpec);
- if (theError=noErr) or (theError=fnfErr) then begin
- if theError=fnfErr then begin
- theError:=FSpCreate(prefFileSpec,
- ApplicationCreator,
- 'pref',
- smSystemScript);
- if theError=noErr then
- SavePreferences(thePreferences,sizeOfPreferences,preferencesName);
- end else
- if theError=noErr then begin
- theError:=FSpOpenDF(prefFileSpec,fsCurPerm,prefFileRef);
- if theError=noErr then begin
- theError:=FSRead(prefFileRef,sizeOfPreferences,thePreferences);
- theError:=FSClose(prefFileRef);
- end;
- end;
- end;
- end;
- end;
- end;
- end;
-
- procedure SavePreferences(thePreferences:Ptr;sizeOfPreferences:longint;preferencesName:Str32);
- var
- jcgDirName:Str32;
- theError:OSErr;
- prefVolRef,prefFileRef:integer;
- prefDirID,jcgDirID:longint;
- jcgDirSpec,prefFileSpec:FSSpec;
- theCIPB:CInfoPBRec;
- begin
- jcgDirName:='jcg';
- theError:=FindFolder(kOnSystemDisk,kPreferencesFolderType,true,prefVolRef,prefDirID);
- if theError=noErr then begin
- theError:=FSMakeFSSpec(prefVolRef,prefDirID,jcgDirName,jcgDirSpec);
- if theError=noErr then begin
- theCIPB.ioCompletion:=nil;
- theCIPB.ioNamePtr:=@jcgDirName;
- theCIPB.ioVRefNum:=prefVolRef;
- theCIPB.ioDrDirID:=prefDirID;
- theCIPB.ioFDirIndex:=0;
- theError:=PBGetCatInfoSync(@theCIPB);
- jcgDirID:=theCIPB.ioDrDirID;
- if theError=noErr then begin
- theError:=FSMakeFSSpec(prefVolRef,jcgDirID,preferencesName,prefFileSpec);
- if theError=noErr then begin
- theError:=FSpOpenDF(prefFileSpec,fsRdWrPerm,prefFileRef);
- if theError=noErr then begin
- theError:=FSWrite(prefFileRef,sizeOfPreferences,thePreferences);
- theError:=FSClose(prefFileRef);
- end;
- end;
- end;
- end;
- end;
- end;
-
- end.